package com.hig.ledger.service.impl;

import java.util.List;

import com.ruoyi.common.annotation.DataScope;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.framework.web.service.TokenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.hig.ledger.mapper.LedgerReliefMaterialsMapper;
import com.hig.ledger.domain.LedgerReliefMaterials;
import com.hig.ledger.service.ILedgerReliefMaterialsService;

/**
 * 应急救援物资清单Service业务层处理
 *
 * @author scp
 * @date 2024-09-22
 */
@Service
public class LedgerReliefMaterialsServiceImpl implements ILedgerReliefMaterialsService
{
    @Autowired
    private LedgerReliefMaterialsMapper ledgerReliefMaterialsMapper;
    @Autowired
    private TokenService tokenService;

    /**
     * 查询应急救援物资清单
     *
     * @param id 应急救援物资清单ID
     * @return 应急救援物资清单
     */
    @Override
    public LedgerReliefMaterials selectLedgerReliefMaterialsById(Long id)
    {
        return ledgerReliefMaterialsMapper.selectLedgerReliefMaterialsById(id);
    }

    /**
     * 查询应急救援物资清单列表
     *
     * @param ledgerReliefMaterials 应急救援物资清单
     * @return 应急救援物资清单
     */
    @Override
    @DataScope(deptAlias = "d")
    public List<LedgerReliefMaterials> selectLedgerReliefMaterialsList(LedgerReliefMaterials ledgerReliefMaterials)
    {
        return ledgerReliefMaterialsMapper.selectLedgerReliefMaterialsList(ledgerReliefMaterials);
    }

    /**
     * 新增应急救援物资清单
     *
     * @param ledgerReliefMaterials 应急救援物资清单
     * @return 结果
     */
    @Override
    public int insertLedgerReliefMaterials(LedgerReliefMaterials ledgerReliefMaterials)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        ledgerReliefMaterials.setCreateBy(loginUser.getUser().getUserName());
        ledgerReliefMaterials.setDeptId(loginUser.getUser().getDeptId());
//        long id = ledgerReliefMaterialsMapper.getNextId();
//        ledgerReliefMaterials.setId(id);
        ledgerReliefMaterials.setCreateTime(DateUtils.getNowDate());
        return ledgerReliefMaterialsMapper.insertLedgerReliefMaterials(ledgerReliefMaterials);
    }

    /**
     * 修改应急救援物资清单
     *
     * @param ledgerReliefMaterials 应急救援物资清单
     * @return 结果
     */
    @Override
    public int updateLedgerReliefMaterials(LedgerReliefMaterials ledgerReliefMaterials)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        ledgerReliefMaterials.setUpdateBy(loginUser.getUser().getUserName());
        ledgerReliefMaterials.setUpdateTime(DateUtils.getNowDate());
        return ledgerReliefMaterialsMapper.updateLedgerReliefMaterials(ledgerReliefMaterials);
    }

    /**
     * 批量删除应急救援物资清单
     *
     * @param ids 需要删除的应急救援物资清单ID
     * @return 结果
     */
    @Override
    public int deleteLedgerReliefMaterialsByIds(Long[] ids)
    {
        return ledgerReliefMaterialsMapper.deleteLedgerReliefMaterialsByIds(ids);
    }

    /**
     * 删除应急救援物资清单信息
     *
     * @param id 应急救援物资清单ID
     * @return 结果
     */
    @Override
    public int deleteLedgerReliefMaterialsById(Long id)
    {
        return ledgerReliefMaterialsMapper.deleteLedgerReliefMaterialsById(id);
    }
}
